﻿
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sproc_Flow_IsNewDocument]') AND type in (N'P', N'PC'))
    DROP PROCEDURE [dbo].[sproc_Flow_IsNewDocument];
GO
CREATE PROCEDURE [dbo].[sproc_Flow_IsNewDocument]
    @DocID int
AS

IF EXISTS(SELECT 1 FROM uds_flow_document WHERE doc_id =@DocID)
BEGIN
    IF EXISTS(
            SELECT 1 
                FROM 
                    uds_flow_document
                WHERE 
                      doc_id         = @DocID
                      AND IsRunning     = 0 )
        RETURN 1
    ELSE
        RETURN 0
END
ELSE
    RETURN -1